home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / util / utilFuncs.c < prev   
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.6 KB  |  219 lines

  1. /*
  2.  *   $RCSfile: utilFuncs.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "sysdefs.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "io.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "link.h"
  52. #include "lsn.h"
  53. #include "latch.h"
  54. #include "bf.h"
  55. #include "volume.h"
  56. #include "pool.h"
  57. #include "server_util_funcs.h"
  58. #include "thread_globals.h"
  59. #include "disk_globals.h"
  60. #include "io_globals.h"
  61. #include "queue_consist.h"
  62. #include "disk_funcs.h"
  63. #include "io_extfuncs.h"
  64.  
  65. #ifdef DEBUG
  66. void
  67. checkMalloc()
  68. {
  69. #ifdef JUNK
  70.     static BOOL first = TRUE;
  71.     static char *prev = NULL;
  72.     char *current;
  73.     current = (char *)sbrk(0);
  74.     if(current != prev) {
  75.         if(!first) {
  76.             TRPRINT(TR_SHM, TR_LEVEL_1, ("Gained %d bytes!", current-prev));
  77.         }
  78.     }
  79.     prev = current;
  80.     first = FALSE;
  81. #endif JUNK
  82. }
  83. #endif DEBUG
  84.  
  85. /* 
  86.  * MonDump(BOOL, volRec)
  87.  * the 1st argument tells whether or not to dump the server process.
  88.  * the 2nd argument has 3 possible semantics:
  89.  *       if null
  90.  *            if environment variable PROFDIR is set, do all disk processes
  91.  *            else don't bother with disk processes
  92.  *       else points to volume to kick 
  93.  */
  94. #ifdef PROFIL
  95. BEGIN_EXTERNC
  96.     extern void  monitor(int);
  97.     extern void  moncontrol(int);
  98. END_EXTERNC
  99.  
  100. static BOOL
  101. ifOpenDoDump(
  102.     VOLREC         *volRec,
  103.     DISKMSG        *diskmessage,
  104.     int            *errloc
  105. {
  106.     int error = 0;
  107.  
  108.     SM_ASSERT(LEVEL_1, (volRec->volflags & VOL_OPEN) );
  109.  
  110.     if(volRec->diskrwPid) {
  111.         if(callDisk(volRec, diskmessage)) 
  112.             error = Active->errno;
  113.     }
  114.     if(error)
  115.         *errloc = error;
  116.     return FALSE;
  117. }
  118. #endif PROFIL
  119.  
  120.  int
  121. MonDump (
  122.     BOOL            unused1,
  123.     VOLREC            *unused2
  124. )
  125. {
  126. #ifdef PROFIL
  127.     DISKMSG            *diskmessage;
  128.     int error;
  129.  
  130.     /* All this is under control of -DPROFIL so that
  131.      * one can make a version of the server that
  132.      * doesn't require the -p option (to get monstartup, etc
  133.      * linked in).
  134.      * The idea is that you compile with -p -DPROFIL or with
  135.      * neither.  
  136.      */
  137.  
  138.  
  139.     if(unused1) {
  140.         /* 
  141.          * cease monitoring for the moment, and write the
  142.          * mon.out file 
  143.          */
  144.         monitor(0); 
  145.         /* 
  146.          * resume, using the original buffer
  147.          */
  148.         moncontrol(1); 
  149.     }
  150.  
  151.     /* 
  152.      * Now tell diskrw(s) to do the same...
  153.      */
  154.     SM_ASSERT(LEVEL_1, Active!=NULL);
  155.     diskmessage = Active->diskMessage;
  156.     diskmessage->header.type = DUMP_MON;
  157.  
  158.     if(unused2) {
  159.         ifOpenDoDump(unused2, diskmessage, &error);
  160.     } else if(HasProfDir) {
  161.         ForEachVolume(2, ifOpenDoDump, diskmessage, &error, 0);
  162.     }
  163.     return error;
  164. #else PROFIL
  165.     return esmNOTIMPLEMENTED;
  166. #endif PROFIL
  167. }
  168.  
  169.  
  170.  void
  171. DumpCore ()
  172. {
  173.     fprintf(stderr, "SERVER %d aborting; creating core file...\n", getpid());
  174.     abort();
  175. }
  176.  
  177.  
  178. #ifdef DEBUG
  179. #include "distr.h"
  180. #include "distr_globals.h"
  181.  
  182. int
  183. DebugSetVar(int var, int value)
  184. {
  185.     switch(var) {
  186.     case 0:
  187.         break;
  188.     case 1:
  189.         DebugDistrVote = value;
  190.         break;
  191.     case 2:
  192.         DebugCrashLoc = value;
  193.         break;
  194.     default:
  195.         fprintf(sm_ErrorStream, "Unknown debug variable %d", var);
  196.         return esmFAILURE;
  197.     }
  198.     return esmNOERROR;
  199. }
  200. int
  201. DebugGetVar(int var, int *value)
  202. {
  203.     switch(var) {
  204.     case 0:
  205.         break;
  206.     case 1:
  207.         *value = DebugDistrVote;
  208.         break;
  209.     case 2:
  210.         *value = DebugCrashLoc;
  211.         break;
  212.     default:
  213.         return esmFAILURE;
  214.     }
  215.     return esmNOERROR;
  216. }
  217. #endif DEBUG
  218.